package org.jojo.sort;

import java.util.Arrays;

/**
 * @author xiexiong
 */
public class SelectionSort {
    public static int[] selectSort(int[] nums){
        int length = nums.length;
        int minIndex = 0;
        for(int i=0;i<length;i++){
             minIndex = i;
            for(int j = i+1;j<length;j++){
                if(nums[j]<nums[minIndex]){
                    minIndex = j;
                }
            }
            swap(nums, minIndex, i);
        }
        return nums;
    }
    public static void swap(int[] arr ,int i,int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{4, 10, 3, 5, 1, 2};
        selectSort(arr);
        System.out.println(Arrays.toString(arr));
    }
}
